<html>

	<head>
		<meta charset="UTF-8">
		<title>新增燃气公司</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<link rel="stylesheet" href="../../layui/css/layui.css" />
		<link rel="stylesheet" href="../../css/bass.css" />
		<style>
			.layui-form {
				width: 35%;
			}
			
			.layui-input {
				width: 100% !important;
			}
		</style>
	</head>

	<body>
		<div class="body">
			<header class="layui-nav" id="headerTop"></header>
			<div class="left_muen" id="left_menu"></div>
			<div class="content_body">

				<!--标题栏-->
				<p class="content_title">账号管理 &nbsp;&nbsp;>&nbsp;&nbsp;新增燃气公司</p>
				<!--标题栏-->

				<form class="layui-form mt20">
					<div class="layui-form-item">
						<label class="layui-form-label">账号</label>
						<div class="layui-input-block">
							<input type="text" name="userAccount" lay-verify="required" autocomplete="off" placeholder="请输入账号" class="layui-input w30" style="display: inline;">
							<!--*（英文和数字组成）-->
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">公司简称</label>
						<div class="layui-input-block">
							<input type="text" name="userCompany" lay-verify="required" placeholder="请输入公司简称" autocomplete="off" class="layui-input w30">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">公司全称</label>
						<div class="layui-input-block">
							<input type="text" name="userCompanyAllTitle" lay-verify="required" placeholder="请输入公司全称" autocomplete="off" class="layui-input w30">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">密码</label>
						<div class="layui-input-block">
							<input type="password" name="userPwd" lay-verify="pass" placeholder="请输入密码" autocomplete="new-password" class="layui-input w30" style="display: inline;">请填写6到12位密码
						</div>
					</div>
					<div class="layui-form-item">
						<!--<div class="layui-inline">-->
						<label class="layui-form-label">状态</label>
						<div class="layui-input-block">
							<select name="userStatus" lay-verify="required" lay-search="">
								<option value="">请选择</option>
								<option value="0">正常</option>
								<option value="1">禁用</option>
							</select>
						</div>
						<!--</div>-->
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">联系人名字</label>
						<div class="layui-input-block">
							<input type="text" name="linkmanName" lay-verify="required" placeholder="请输入联系人名字" class="layui-input w30">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">联系方式</label>
						<div class="layui-input-block">
							<input type="text" name="linkmanPhone" lay-verify="required|phone" placeholder="请输入联系方式" class="layui-input w30">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">邮箱</label>
						<div class="layui-input-block">
							<input type="text" name="userEmail" lay-verify="required|email" placeholder="邮箱" autocomplete="new-password" class="layui-input w30">
						</div>
					</div>
					<div class="layui-form-item layui-form-text">
						<label class="layui-form-label">描述</label>
						<div class="layui-input-block">
							<textarea name="userDesc" id="userDesc" placeholder="请输入描述" class="layui-textarea"></textarea>
						</div>
					</div>

					<div class="layui-form-item">
						<label class="layui-form-label">logo</label>
						<div class="layui-input-block">
							<button type="button" class="layui-btn layui-btn-primary" id="fileUrl">
								<i class="layui-icon">&#xe67c;</i>选择图片
							</button>
							<button type="button" class="layui-btn layui-btn-warm" id="uploadBtn">开始上传</button></br>
							<!--<input type="text" name="userLogoUrl" id="userLogoUrl" value="/herta.png">-->
							<input type="hidden" name="userLogoUrl" id="userLogoUrl" value="" class="layui-input w30">
						</div>
					</div>
					<!--<div class="layui-form-item">
						<label class="layui-form-label"></label>
						<div class="layui-input-block">
							<input type="hidden" name="userLogoUrl" id="userLogoUrl" value="" class="layui-input w30">
						</div>
					</div>-->
					<div class="layui-form-item">
						<div class="layui-input-block">
							<!--预览图片-->
							<div class="layui-upload-list" id="showblock"></div>
						</div>
					</div>

					<div class="layui-form-item">
						<div class="layui-input-block">
							<div class="layui-btn" lay-submit="" lay-filter="submitFilter">立即提交</div>
							<button type="reset" class="layui-btn layui-btn-primary">重置</button>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../js/common/jquery-1.11.3.min.js"></script>
		<script src="../../layui/layui.js"></script>
		<script src="../../js/common/navList.js"></script>
		<script src="../../js/common/ajax.js"></script>
		<script>
			layui.use(['form', 'layedit', 'upload'], function() {
				var form = layui.form,
					layer = layui.layer,
					layedit = layui.layedit,
					upload = layui.upload;

				//监听提交
				form.on('submit(submitFilter)', function(data) {
					if(data.field.userLogoUrl == "") {
						layer.msg('请上传图片', {
							icon: 5
						});
						return;
					};
					ajaxPost({
						url: 'user/add',
						data: {
							userType: 1, //用户类型 0admin甲方 1燃气公司账号 2下游账号 3普通用户
							roleIds: 17, //燃气公司角色
							userAccount: data.field.userAccount, //账号
							userCompany: data.field.userCompany, //公司简称
							userCompanyAllTitle: data.field.userCompanyAllTitle, //公司全称
							userPwd: data.field.userPwd, //密码
							userStatus: data.field.userStatus, //状态
							linkmanName: data.field.linkmanName, //联系人名字
							linkmanPhone: data.field.linkmanPhone, //联系方式
							userLogoUrl: baseUrl+'file/'+ data.field.userLogoUrl, //logo
							userDesc: data.field.userDesc, //描述
							userEmail: data.field.userEmail, //邮箱
						},
						successFull: function(res) {
							console.log(res)
							if(res.code == 200) {
								layer.msg('添加成功', {
									icon: 6
								});
								window.location.href = "./adminList.html?pos=5&childPos=0";
							} else {
								layer.msg('添加失败', {
									icon: 5
								});
							}
						},
						errCallBack: function(res) {
							layer.msg(res.msg, {
								icon: 5
							});
						}
					})
				});

				//执行实例
				var userLogoUrl = [];
				var uploadInst = upload.render({
					elem: "#fileUrl", //绑定元素
					url: baseUrl + "contract/upload", //上传接口
					field: "file", //设定文件域的字段名
					accept: "file", //指定允许上传时校验的文件类型，可选值有：images（图片）、file（所有文件）、video（视频）、audio（音频）
					auto: false,
					bindAction: '#uploadBtn',
					multiple: true,
					choose: function(obj) { //文件上传前的回调
						console.log(obj);
						//预读本地文件示例，不支持ie8
						obj.preview(function(index, file, result) {
							$('#showblock').html('<img src="' + result + '" alt="' + file.name + '" class="layui-upload-img" style="width:100px;height:100px;border: 1px solid #d0caca;margin: 5px;"  >')
						});
					},
					done: function(res) {
						//上传完毕回调
						console.log(res);
						if(res.code == 200) {
							userLogoUrl = res.msg;
							console.log(userLogoUrl);
							$("#userLogoUrl").val(userLogoUrl);
							layer.msg('上传成功', {
								icon: 6
							});
						} else {
							layer.msg('上传失败', {
								icon: 5
							});
						}
					},
					error: function(res) {
						//请求异常回调
						console.log(res);
					}
				});

			});
		</script>
	</body>

</html>